package com.example.zhangxin.comevedio.activity.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.example.zhangxin.comevedio.activity.MyApplication;

/**
 * Created by ZhangXin on 2016/9/13.
 */

public class ShareprefreceUtils {
    public static final String PREFRECE_NAME="login_info";
    public static final String APP_KEY_PWD="app_key_pwd";
    public static final String  APP_SETUP_PROGARD="app_setup_progard";

    public static void write(String name,String value){
        SharedPreferences sp = MyApplication.getContent().getSharedPreferences(PREFRECE_NAME, Context.MODE_PRIVATE);
        if(sp!=null&&!TextUtils.isEmpty(name)){
            SharedPreferences.Editor edit = sp.edit();
            edit.putString(name,value);
            edit.commit();
        }
    }
    public static void write(String name,boolean value){
        SharedPreferences sp = MyApplication.getContent().getSharedPreferences(PREFRECE_NAME, Context.MODE_PRIVATE);
        if(sp!=null&&!TextUtils.isEmpty(name)){
            SharedPreferences.Editor edit = sp.edit();
            edit.putBoolean(name,value);
            edit.commit();
        }
    }

    public static String read(String name,String defaultValue){
        SharedPreferences sp= MyApplication.getContent().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
        return sp == null ? defaultValue : sp.getString(name,defaultValue);
    }
    public static boolean read(String name, boolean defaultValue){
        SharedPreferences sp= MyApplication.getContent().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
        return sp == null ? defaultValue : sp.getBoolean(name,defaultValue);
    }
    public static void clear(){
        SharedPreferences sp = MyApplication.getContent().getSharedPreferences(PREFRECE_NAME, Context.MODE_PRIVATE);
        sp.edit().clear().commit();

    }
}
